﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using t_DeepTalkRenderServiceLib.DTDBService;
using System.Threading;
using DeepTalkRenderServiceLib;
using IndicoInterface;

namespace t_DeepTalkRenderServiceLib
{
    [TestClass]
    public class t_RenderMeetings
    {
        public TestContext TestContext { get; set; }
        
        [TestInitialize]
        public void InitTest()
        {
            Utils.StartMainService();
            FileInfo db = new FileInfo("ConfData_" + TestContext.TestName + ".sdf");
            File.Copy(@"..\..\..\DeepTalkDBService\ConferenceData.sdf", db.FullName);
            using (DTDBClient rc = new DTDBClient())
            {
                rc.SetDBFile(db);
            }
        }

        [TestCleanup]
        public void TestCleanup()
        {
            Utils.ShutdownMainService();
        }

        [TestMethod]
        [Timeout(10 * 1000)]
        public void TestRenderTwoMeetings()
        {
            Utils.SubmitTalk("http://indico.cern.ch/conferenceDisplay.py?confId=a042880");
            Utils.SubmitTalk("http://agenda.hep.wisc.edu/conferenceTimeTable.py?confId=60");

            AutoResetEvent ar = new AutoResetEvent(false);
            int count = 2;
            var t = RenderMeetings.Start((strXML, id) =>
            {
                var result = new RenderMeetingTask.RenderResultsInfo()
                {
                    HowLongToNextUpdate = null,
                    NumberOfTalks = 10,
                    SizeOfRender = (float)5.0
                };
                count--;
                if (count == 0)
                {
                    ar.Set();
                }
                return result;
            }, "Net.TCP");
            ar.WaitOne();
            Assert.AreEqual(0, count, "Didn't see both talks go by! Weird!");
        }
    }
}
